package com.epoint.rest;

import com.epoint.springtest.User;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
public class HtmlIndex {

    @RequestMapping(value = {"/index"})
    public String index(){
        return "index.html";
    }

    @RequestMapping(value = {"/tologin", "/"})
    public String toLogin(){
        return "login.html";
    }

    @PostMapping("/topasslogin")
    public String login(String username, String password, HttpSession session){

        if(!StringUtils.isEmpty(password)){
            User user = new User();
            user.setUserName(username);
            user.setPassWord(password);
            user.setName("纪宽豪");
            session.setAttribute("user", user);
            // 登录之后 重定向
            return "redirect:/main.html";
        }else{
            return "/tologin";
        }
    }

    @GetMapping("/ceshilogin")
    public String ceshilogin(){
        return "index.html";
    }

    @GetMapping("/basic_table.html")
    public String basic_table(){
        return "table/basic_table.html";
    }

    @GetMapping("/dynamic_table.html")
    public String dynamic_table(){
        return "table/dynamic_table.html";
    }

    @GetMapping("/editable_table.html")
    public String editable_table(){
        return "table/editable_table.html";
    }


}
